<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 * @author   howe <howe1995@163.com>
 */
use Hyperf\Database\Migrations\Migration;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Schema\Schema;

return new class() extends Migration {
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('group_users', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('group_id')->default(0)->comment('群ID');
            $table->unsignedBigInteger('user_id')->comment('群成员ID');
            $table->enum('role', ['user', 'super', 'admin', 'assistant'])->default('user')->comment('角色');
            $table->Integer('invite_id')->comment('邀请人ID');
            $table->tinyInteger('invite_type')->unsigned()->default(1)->comment('邀请类型');
            $table->string('name', 50)->default('')->comment('群备注');
            $table->string('nickname', 50)->default('')->comment('我在本群昵称');
            $table->integer('unread')->unsigned()->default(0)->comment('未读消息数');
            $table->integer('top')->unsigned()->default(0)->comment('置顶时间');
            $table->tinyInteger('display')->unsigned()->default(1)->comment('是否显示');
            $table->tinyInteger('muted')->unsigned()->default(0)->comment('是否免打扰');
            $table->tinyInteger('display_nickname')->unsigned()->default(1)->comment('是否显示群成员昵称');
            $table->integer('bg_file_id')->unsigned()->default(0)->comment('背景图ID(对应files里的ID)');
            $table->string('bg_file_path', 255)->default('')->comment('背景图路径');
            $table->json('setting');
            $table->timestamp('created_at')->useCurrent();
            $table->timestamp('updated_at')->useCurrent();
            $table->integer('deleted_at')->nullable()->default(null);
            $table->unique(['group_id', 'user_id'], 'uk_group_id_user_id', 'BTREE');
            $table->comment('群成员表');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('group_users');
    }
};
